Arduino Cookbook by Michael Margolis

Arduino Cookbook by Michael Margolis

Author:Michael Margolis [Michael Margolis]
Language: eng
Format: epub, mobi
Tags: TECHNOLOGY & ENGINEERING / Robotics
ISBN: 9781449313906
Publisher: O'Reilly Media
Published: 2011-12-11T16:00:00+00:00


Note

You won’t see anything when the codes are sent because the light from the infrared LED isn’t visible to the naked eye.

However, you can verify that an infrared LED is working with a digital camera—you should be able to see it flashing in the camera’s LCD viewfinder.

Figure 10-2. Buttons and LED for IR sender

Discussion

Here Arduino controls the device by flashing an IR LED to duplicate the signal that would be sent from your remote control. This requires an IR LED. The specifications are not critical; see Appendix A for suitable components.

The IR library handles the translation from numeric code to IR LED flashes. You need to create an object for sending IR messages. The following line creates an IRsend object that will control the LED on pin 3 (you are not able to specify which pin to use; this is hardcoded within the library):

IRsend irsend;

The code uses an array (see Recipe 2.4) called irKeyCodes to hold the range of values that can be sent. It monitors five switches to see which one has been pressed and sends the relevant code in the following line:

irsend.sendSony(irKeyCodes[keyNumber], 32);

The irSend object has different functions for various popular infrared code formats, so check the library documentation if you are using one of the other remote control formats. You can use Recipe 10.2 if you want to display the format used in your remote control.

The sketch passes the code from the array, and the number after it tells the function how many bits long that number is. The 0x at the beginning of the numbers in the definition of irKeyCodes at the top of the sketch means the codes are written in hex (see Chapter 2 for details about hex numbers). Each character in hex represents a 4-bit value. The codes here use eight characters, so they are 32 bits long.

The LED is connected with a current-limiting resistor (see the introduction to Chapter 7).

If you need to increase the sending range, you can use multiple LEDs or select one with greater output.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.